import { useUserStore } from "@/store/userState";
import { LeftOutline } from "antd-mobile-icons";
import { useNavigate } from "react-router-dom";

// import { useRouter } from "next/router";
export default function LoginPage({ goBack }: { goBack: () => void }) {
  const { setUser } = useUserStore();

  // const router = useRouter();
  const navigate = useNavigate();
  globalThis.onmessage = (event) => {
    const { data } = event;
    const { payload, source } = data;
    if (source !== "mars-platform") return;
    console.log(payload);
    setUser("admin", payload);
    // Toast.show({
    //   content: "已登录",
    //   afterClose() {
    //     navigate("/locate", { replace: true }); // 收到登录成功的事件后可以根据需要跳到任意页面。
    //   },
    // });
    setTimeout(() => {
      navigate("/locate"); // 收到登录成功的事件后可以根据需要跳到任意页面。
    }, 1500);
  };
  return (
    <div className='fixed w-full h-full'>
      <div className='absolute left-10 top-10' onClick={goBack}>
        <LeftOutline fontSize={28} />
      </div>
      <iframe
        id='senseMagic'
        title='Login page for sense magic'
        src={window.IFRAME}
        width='100%'
        height='100%'></iframe>
    </div>
  );
}
